// 使用 import type 专门导入类型
import type { MockMethod } from 'vite-plugin-mock'
import { md5 } from 'js-md5'
interface LoginRequestBody {
  username: string
  password: string
}
// 明确指定类型为MockMethod数组
const mock: MockMethod[] = [
  {
    url: '/api/login',
    method: 'post',
    response: ({ body }: { body: LoginRequestBody }) => {
      const { username, password } = body
      const databasePassword = md5("123456")
      if (username === 'admin' && password === databasePassword) {
        return {
          code: 200,
          message: '登录成功',
          data: {
            token: 'mock-token-' + Date.now(),
            userInfo: {
              id: 1,
              username: 'admin',
              role: 'admin'
            }
          }
        }
      }
      
      return {
        code: 401,
        message: '用户名或密码错误',
        data: null
      }
    }
  },
  {
    url: '/api/user/info',
    method: 'get',
    response: () => {
      return {
        code: 200,
        message: 'success',
        data: {
          id: 1,
          username: 'admin',
          avatar: 'https://picsum.photos/200/200',
          roles: ['admin']
        }
      }
    }
  }
]

export default mock
    